package com.CmJava.serviceImpl;


import com.CmJava.entity.User;
import com.CmJava.entity.UserDetail;
import com.CmJava.mapper.UserDetailMapper;
import com.CmJava.service.PrivateService;
import com.CmJava.mapper.PrivateMapper;
import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class PrivateServiceImpl implements PrivateService {

    @Autowired
    private PrivateMapper privateMapper;

    @Autowired
    private UserDetailMapper userDetailMapper;



    @Override
    public String getFriendList(String userName) {
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("userName",userName);
        User user = privateMapper.selectOne(userQueryWrapper);
        return user.getFriendList();
    }

    @Override
    public List<UserDetail> getFriendDetail(String userName, String friendList) {
        UserDetail userDetail=null;
        ArrayList<UserDetail> userDetails = new ArrayList<>();

        for (String friendName : friendList.split(",")) {
            QueryWrapper<UserDetail> userDetailQueryWrapper = new QueryWrapper<>();
            userDetailQueryWrapper.eq("username",friendName);
            userDetail = userDetailMapper.selectOne(userDetailQueryWrapper);
            userDetails.add(userDetail);
        }

        return userDetails;
    }
}
